package com.example.securitydemo.validation;

import com.example.securitydemo.domain.dto.UserDto;
import com.example.securitydemo.validation.annotation.ValidPasswordMatch;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class PasswordMatchValidator implements ConstraintValidator<ValidPasswordMatch, UserDto> {

    @Override
    public void initialize(ValidPasswordMatch constraintAnnotation) {}

    @Override
    public boolean isValid(UserDto userDto, ConstraintValidatorContext context) {
        return userDto.getPassword().equals(userDto.getMatchingPassword());
    }

}
